﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using Convertor.Interface;
using Wpf.CommonTools.EnumExtension;
using Wpf.CommonTools.SystemExtension;

namespace Convertor.Plugin.FindAllFiles
{
    [Flags]
    public enum FindTypes
    {
        FindFiles = 1,
        FindFolder = 2,
        FindSubFolder = 4
    }

    [Serializable]
    public class ConfigContent : IConfigContent, ISerializable, ICloneable, INotifyPropertyChanged
    {
        private FindTypes findType = FindTypes.FindFiles | FindTypes.FindSubFolder;

        public FindTypes FindType
        {
            get { return findType; }
            set { findType = value; if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("ToolTip")); } }
        }

        public ConfigContent()
        {
        }

        public override string ToString()
        {
            return ToolTip;
        }

        #region IToolTip 成员

        public string ToolTip
        {
            get
            {
                var b = this.findType.GetFlags().Select(p => UILanguage.TryFindResource("Plugin_FindAllFile_" + p)).DefaultIfEmpty().Aggregate((k, n) => k + ", " + n);
                return string.Format(UILanguage.FindResource("Plugin_FindAllFile_Info"), b);
            }
        }

        #endregion

        #region ISerializable 成员

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("FindType", FindType, typeof(FindTypes));
        }

        public ConfigContent(SerializationInfo info, StreamingContext context)
        {
            findType = (FindTypes)info.GetValue("FindType", typeof(FindTypes));
        }

        #endregion

        #region ICloneable 成员

        public object Clone()
        {
            ConfigContent a = new ConfigContent()
            {
                FindType = this.FindType
            };
            return a;
        }

        #endregion

        #region INotifyPropertyChanged 成员

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }

}
